home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
M2Crypto
/
m2urllib2.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
3KB
|
93 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from urllib2 import *
import urlparse
import SSL
import httpslib
class HTTPSHandler(AbstractHTTPHandler):
def __init__(self, ssl_context = None):
AbstractHTTPHandler.__init__(self)
if ssl_context is not None:
self.ctx = ssl_context
else:
self.ctx = SSL.Context()
def https_open(self, req):
host = req.get_host()
if not host:
raise URLError('no host given')
full_url = req.get_full_url()
target_host = urlparse.urlparse(full_url)[1]
if target_host != host:
h = httpslib.ProxyHTTPSConnection(host = host, ssl_context = self.ctx)
else:
h = httpslib.HTTPSConnection(host = host, ssl_context = self.ctx)
h.set_debuglevel(self._debuglevel)
headers = dict(req.headers)
headers.update(req.unredirected_hdrs)
headers['Connection'] = 'close'
try:
h.request(req.get_method(), req.get_full_url(), req.data, headers)
r = h.getresponse()
except socket.error:
err = None
raise URLError(err)
r.recv = r.read
fp = socket._fileobject(r)
resp = addinfourl(fp, r.msg, req.get_full_url())
resp.code = r.status
resp.msg = r.reason
return resp
https_request = AbstractHTTPHandler.do_request_
def build_opener(ssl_context = None, *handlers):
opener = OpenerDirector()
default_classes = [
ProxyHandler,
UnknownHandler,
HTTPHandler,
HTTPDefaultErrorHandler,
HTTPRedirectHandler,
FTPHandler,
FileHandler,
HTTPErrorProcessor]
skip = []
for klass in default_classes:
for check in handlers:
if inspect.isclass(check):
if issubclass(check, klass):
skip.append(klass)
issubclass(check, klass)
if isinstance(check, klass):
skip.append(klass)
continue
for klass in skip:
default_classes.remove(klass)
for klass in default_classes:
opener.add_handler(klass())
if HTTPSHandler not in skip:
opener.add_handler(HTTPSHandler(ssl_context))
for h in handlers:
if inspect.isclass(h):
h = h()
opener.add_handler(h)
return opener